<?php
session_start();
$username = $_SESSION['username'];
$currentEmail = $_POST['currentemail'];
$newEmail = $_POST['Newemail'];
$confirmEmail = $_POST['confirmemail'];
$phone = $_POST['phone'];

$mysql_host = "mysql16.000webhost.com";
$mysql_database = "a1863493_venture";
$mysql_user = "a1863493_teamven";
$mysql_password = "teamventure1";

$link = mysql_connect($mysql_host, $mysql_user, $mysql_password); 
	
if (!$link) 
{
	die('Could not connect: ' . mysql_error());
} 
echo 'Connected successfully'; 

mysql_select_db($mysql_database, $link) or die ("Fail");

//change email
$query = sprintf("SELECT email FROM cust_acct WHERE name = '$username'");
$return = mysql_query($query);
if (mysql_num_rows($return)){
$result = mysql_result($return,0);

	if( $result == $currentEmail )
	{

		if( $newEmail == $confirmEmail && isset($newEmail) )
		{
			echo "test";
			$query = sprintf("UPDATE cust_acct SET email = '$newEmail' WHERE name = '$username'");
			$return = mysql_query($query);
		}
	}

}

$query = mysql_query("UPDATE cust_acct SET phone = '$phone' WHERE name = '$username'");



		header ('Location: ../userPref.html');
?>